package ThreadDemo;

import java.util.HashMap;

//第五天
public class leetcode6 {
    public int minArray(int[] numbers) {
        int left=0;
        int right=numbers.length-1;
        int min=Integer.MAX_VALUE;
        while (left<right){
            int mid=(left+right)/2;
            if (numbers[mid]<numbers[right]){
                right=mid;
            }else if(numbers[mid]>numbers[left]){
                left=mid;
            }else {
                right-=1;
            }
        }
        return numbers[left];
    }
    public char firstUniqChar(String s) {
        HashMap<Character,Integer>hashMap=new HashMap<>();
        for (char i:s.toCharArray()) {
            if (hashMap.containsKey(i)){
                hashMap.put(i,hashMap.get(i)+1);
            }else {
                hashMap.put(i,1);
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if(hashMap.get(s.charAt(i))==1){
                return s.charAt(i);
            }
        }
        return ' ';
    }
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix.length==0||matrix[0].length==0){
            return false;
        }
        int i=0;
        int j=matrix[0].length-1;
        while(i<matrix.length&&j>=0){
            if(target==matrix[i][j]){
                return true;
            }else if(target>matrix[i][j]){
                i++;
            }else{
                j--;
            }
        }
        return false;

    }


}
